package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.vo.CategoryNestedVo;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品分类 前端控制器
 * </p>
 *
 * @author Haoran Sun
 * @since 2024-07-15
 */
@RestController
@RequestMapping("/category")
@Tag(name = "商品的分类信息管理")
public class CategoryController extends BaseController {

    @Resource
    private CategoryService categoryService;

    /**
     * 根据父分类的id获取分类列表
     * @param parentId 父分类的id
     * @return 子分类的分类信息
     */
    @Operation(summary = "根据父分类的id获取分类列表")
    @GetMapping("treeSelect/{parentId}")
    public AjaxResult getCategoryListByParentId(@PathVariable("parentId") Long parentId) {
        return success(categoryService.getCategoryListByParentId(parentId));
    }

    /**
     * @code @InnerAuth 表示此接口为内部调用接口
     * @return 一级分类列表
     */
    @InnerAuth
    @GetMapping(value = "/getOneCategory")
    @Operation(summary = "获取一级分类列表")
    public R<List<CategoryVo>> getOneCategory() {
        return R.ok(categoryService.getOneCategory());
    }

    /**
     * 获取分类树
     * @return 分类树
     */
    @InnerAuth
    @GetMapping(value = "/tree")
    @Operation(summary = "获取分类树")
    public R<List<CategoryNestedVo> > tree() {
        return R.ok(categoryService.tree());
    }
}
